package com.share.wechat.core.repository.inter;

import com.share.wechat.core.entity.QuoteDetail;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface QuoteDetailRepository extends CrudRepository<QuoteDetail, String> {

    /**
     * 根据商品的id来查询具体的信息
     *
     * @param detailId 商品id
     * @return QuoteDetail
     */
    QuoteDetail findByDetailId(String detailId);


    /**
     * 使用detailId 来更新表中结果
     *
     * @param detail detail 要更新的实体集合
     */
    @Modifying
    @Query("update QuoteDetail d set d.descItem = :#{#detail.descItem}, d.price= :#{#detail.price}, " +
            "d.salesVolume = :#{#detail.salesVolume}  where d.detailId = :#{#detail.detailId}")
    void updateByDetailId(@Param("detail") QuoteDetail detail);
}
